import {call,put} from 'redux-saga/effects'
import axios from '../utils/request'
import { message} from 'antd';

export function * getEvaluat({payload}){//获取规格
    console.log(payload,'getEvaluat-payload')
    const res=yield call(axios,{url:'/api/evaluat',method:'get',params:payload})
    console.log(res)
    if(res.code===1){
        yield put({
            type:'GET_EVALUAT',
            payload:res.data
        })
    }else{
        yield put({
            type:'GET_EVALUAT',
            payload:res.data
        })
    }
}

export function * edmitEvaluat({payload}){  //编辑
    console.log(payload,'edmit-payload')
    const res=yield call(axios,{url:'/api/edmitevaluat',method:'put',data:payload})
    console.log(res)
    if(res.code===1){
        message.success(res.data.msg);
        
    }else{
        message.error(res.data.msg);
    }
}

export function * delEvaluat({payload}){//删除商品评价
    console.log(payload,'del-id')
    const res=yield call(axios,{url:`/api/delevaluat/${payload}`,method:'delete'})
    console.log(res)
    if(res.code===1){
        message.success(res.data.msg);
    }else{
        message.error(res.data.msg);
    }
}

export function * addEvaluat({payload}){//新增商品评价
    console.log(payload,'add-id')
    const res=yield call(axios,{url:'/api/addevaluat',method:'post',data:payload})
    console.log(res)
    if(res.code===1){
        message.success(res.data.msg);
        window.location.reload()
    }else{
        message.error(res.data.msg);
    }
}